package com;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.UnknownHostException;
import java.util.Base64;
import java.util.List;
import java.util.Random;

@SpringBootApplication
@RestController
@EnableApolloConfig
public class TestApplication {


    @Autowired
    JdbcTemplate template;
//    @Autowired
//    RedisTemplate redisTemplate;

    private static final Random RANDOM = new Random();
    private static final Logger logger = LoggerFactory.getLogger(TestApplication.class);
    public static void main(String[] args) throws UnknownHostException {

        System.getProperties();

        System.out.println(new String( Base64.getEncoder().encode("ef@123.com".getBytes())));


        SpringApplication application = new SpringApplication(TestApplication.class);
        application.run(args);

    }

    @GetMapping("/test")
    public String test(){
        System.out.println("test is execute");
        logger.info("test is execute");
        logger.error("test is execute");


        return "test is execute ";
    }


    @GetMapping("/testOfredis")
    public String testOfredis(){
        System.out.println("testOfredis is execute");
        logger.info("testOfredis is execute");
        logger.error("testOfredis is execute");
//        redisTemplate.opsForValue().set("k1", "v1");
//        Object o = redisTemplate.opsForValue().get("k1");
//        System.out.println(o);

        return "test is execute ";
    }



    @GetMapping("/find")
    public  List find(){
        System.out.println("find is execute");
        logger.info("find is execute");
        logger.error("find is execute");

        String sql="select * from o_order";
        List<Order> order = template.query(sql
                ,new BeanPropertyRowMapper<>(Order.class));
        logger.info("order is {}",order.toString());
        return order;
    }

}
